package com.ruoyi.thgd.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.thgd.mapper.ThgdJsdHjcsMapper;
import com.ruoyi.thgd.domain.ThgdJsdHjcs;
import com.ruoyi.thgd.service.IThgdJsdHjcsService;

/**
 * 退化耕地- 紧实度 -环境参数Service业务层处理
 *
 * @author chenhs
 * @date 2024-09-11
 */
@Service
public class ThgdJsdHjcsServiceImpl implements IThgdJsdHjcsService
{
    @Autowired
    private ThgdJsdHjcsMapper thgdJsdHjcsMapper;

    /**
     * 查询退化耕地- 紧实度 -环境参数
     *
     * @param id 退化耕地- 紧实度 -环境参数主键
     * @return 退化耕地- 紧实度 -环境参数
     */
    @Override
    public ThgdJsdHjcs selectThgdJsdHjcsById(Integer id)
    {
        return thgdJsdHjcsMapper.selectThgdJsdHjcsById(id);
    }

    /**
     * 查询退化耕地- 紧实度 -环境参数列表
     *
     * @param thgdJsdHjcs 退化耕地- 紧实度 -环境参数
     * @return 退化耕地- 紧实度 -环境参数
     */
    @Override
    public List<ThgdJsdHjcs> selectThgdJsdHjcsList(ThgdJsdHjcs thgdJsdHjcs)
    {
        return thgdJsdHjcsMapper.selectThgdJsdHjcsList(thgdJsdHjcs);
    }

    /**
     * 新增退化耕地- 紧实度 -环境参数
     *
     * @param thgdJsdHjcs 退化耕地- 紧实度 -环境参数
     * @return 结果
     */
    @Override
    public int insertThgdJsdHjcs(ThgdJsdHjcs thgdJsdHjcs)
    {
        String hjId = thgdJsdHjcs.getHjId();
        ThgdJsdHjcs hjcsQuery = new ThgdJsdHjcs();
        hjcsQuery.setHjId(hjId);
        List<ThgdJsdHjcs> hjcsList = thgdJsdHjcsMapper.selectThgdJsdHjcsList(hjcsQuery);
        if(hjcsList.size() > 0) {
            for (ThgdJsdHjcs hjcs : hjcsList){
                thgdJsdHjcsMapper.deleteThgdJsdHjcsById(hjcs.getId());
            }
        }
        thgdJsdHjcs.setCreateTime(DateUtils.getNowDate());
        return thgdJsdHjcsMapper.insertThgdJsdHjcs(thgdJsdHjcs);
    }

    /**
     * 修改退化耕地- 紧实度 -环境参数
     *
     * @param thgdJsdHjcs 退化耕地- 紧实度 -环境参数
     * @return 结果
     */
    @Override
    public int updateThgdJsdHjcs(ThgdJsdHjcs thgdJsdHjcs)
    {
        thgdJsdHjcs.setUpdateTime(DateUtils.getNowDate());
        return thgdJsdHjcsMapper.updateThgdJsdHjcs(thgdJsdHjcs);
    }

    /**
     * 批量删除退化耕地- 紧实度 -环境参数
     *
     * @param ids 需要删除的退化耕地- 紧实度 -环境参数主键
     * @return 结果
     */
    @Override
    public int deleteThgdJsdHjcsByIds(Integer[] ids)
    {
        return thgdJsdHjcsMapper.deleteThgdJsdHjcsByIds(ids);
    }

    /**
     * 删除退化耕地- 紧实度 -环境参数信息
     *
     * @param id 退化耕地- 紧实度 -环境参数主键
     * @return 结果
     */
    @Override
    public int deleteThgdJsdHjcsById(Integer id)
    {
        return thgdJsdHjcsMapper.deleteThgdJsdHjcsById(id);
    }

    @Override
    public ThgdJsdHjcs selectThgdJsdHjcsNew(){
        return thgdJsdHjcsMapper.selectThgdJsdHjcsNew();
    }

    @Override
    public List<ThgdJsdHjcs> selectThgdJsdHjcsListGroupByDate(ThgdJsdHjcs thgdJsdHjcs){
        return thgdJsdHjcsMapper.selectThgdJsdHjcsListGroupByDate(thgdJsdHjcs);

    }
}
